//ajax模板
function jshtml(data, scriptdom) {
    var mainmax = document.getElementById('mainlist');
    var html = "";
    for (var k in data) {
        var htmlm = scriptdom.innerHTML;
        htmlm = htmlm.replace(/\{\{src\}\}/, data[k].good_img);
        htmlm = htmlm.replace(/\{\{num\}\}/, data[k].good_num);
        htmlm = htmlm.replace(/\{\{h3\}\}/g, data[k].good_name);
        htmlm = htmlm.replace(/\{\{price\}\}/, data[k].good_price);
        htmlm = htmlm.replace(/\{\{id\}\}/, data[k].good_id);
        htmlm = htmlm.replace(/\{\{id\}\}/, data[k].good_id);
        html += htmlm;
    }
    mainmax.innerHTML = html;
};
function reEnter () {
    document.querySelector('.infoMsg').style.display = 'block';
    setTimeout(function() {
        window.location.href = '../personal/enter.html';
    },1500);
}
function toDetail(){
    var lists = document.getElementsByClassName("ddd");
    for(var i = 0; i < lists.length; i++){
        Tap(lists[i],function(e,dom){
            var goodId = dom.getAttribute("data-good_id");
            window.location.href = "../detail.html?id="+goodId;
        });
    }
}
window.onload = function(){
    var token = selectByKey("like_token");
    var deliverId = location.search.substr(4);
    var orderMoney = document.querySelector(".p1 i");
    var orderID = document.querySelector(".p2 i");
    var orderAddress = document.querySelector(".p3 i");
    var totalNum = document.getElementById("total_num");
    var yunfei = document.getElementById("yunfei");
    var total = document.getElementById("total");
    var needPay = document.getElementById("needPay");
    var couponPrice = document.getElementById("couponPrice");
    var packingFee = document.getElementById("packingFee");
    var mask = document.querySelector(".mask");
    $.ajax({
        url:pathName+"/api/v1/member/order/"+deliverId,
        type:"GET",
        headers:{
            "Accept":"application/json",
            "Authorization":"Bearer "+token
        },
        success:function(data){
            mask.style.display = "none";
            orderMoney.innerHTML = data.order.pay_total;
            orderID.innerHTML = data.order.order_id;
            orderAddress.innerHTML = data.order.address+"/"+data.order.name+"/"+data.order.phone;
            totalNum.innerHTML = data.order.countGoods;
            yunfei.innerHTML = data.order.trans_cost;
            packingFee.innerHTML = data.order.packingFee + data.order.shortFreight;
            if(data.order.coupon_price){
                couponPrice.innerHTML = "-" + data.order.coupon_price;
            }else{
                couponPrice.innerHTML = 0;
            }
            var couPrice = parseFloat(data.order.coupon_price) || 0;
            total.innerHTML = (parseFloat(data.order.pay_total) + couPrice).toFixed(2);
            needPay.innerHTML = data.order.pay_total;
            jshtml(data.order.goodDetail,listMode);
            toDetail();
            //时间
            var createTime = data.order.created_at.split(" ");
            $(".messg>div:first-child p:nth-child(2)").text(createTime[0]);
            $(".messg>div:first-child p:nth-child(3)").text(createTime[1]);
            var payTime = data.order.order_pay_time.split(" ");
            $(".messg>div:nth-child(2) p:nth-child(2)").text(payTime[0]);
            $(".messg>div:nth-child(2) p:nth-child(3)").text(payTime[1]);
            var outTIme = data.order.order_send_time.split(" ");
            $(".messg>div:nth-child(3) p:nth-child(2)").text(outTIme[0]);
            $(".messg>div:nth-child(3) p:nth-child(3)").text(outTIme[1]);
            var receiveTime = data.order.order_confirm_time.split(" ");
            $(".messg>div:nth-child(4) p:nth-child(2)").text(receiveTime[0]);
            $(".messg>div:nth-child(4) p:nth-child(3)").text(receiveTime[1]);
        },
        error:function(){
            if(!token){
                reEnter();
            }
        }
    })
}
